package cn.butcher21.controller.timeline;


import cn.butcher21.utils.DButil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * butcher create in 2021/03/09/9:29,
 * <p>
 * 返回这个时间对应的内容
 */
@WebServlet("/timeContent")
public class GetTimeContent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String time = request.getParameter("time");
        DButil dButil = new DButil();
        PreparedStatement ps = dButil.getPs("select content from yt_timeline where time=?");
        try {
            ps.setString(1, time);
            ResultSet rs = dButil.getRs(ps.executeQuery());
            if (rs.next()) {
//                获取数据返回，否则就算了
                PrintWriter out = response.getWriter();
                out.print(rs.getString("content"));
                out.flush();
                out.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            dButil.closeAll();
        }
    }
}
